unit mkmwantlistcrawler;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, idHTTP, MkMWantListGlobalTypes, IdMultipartFormData, IdSSLOpenSSL, IdURI;

type

  { TMKMCrawler }

  TMKMCrawler = class
  private
    FExcludedEditions: SetMagicEditions;
  protected
    type
    TMKMCrawlerCardInfo = class

    end;

  protected
    FHTTP: TIdHTTP;
  public
    property ExcludedEditions: SetMagicEditions read FExcludedEditions write FExcludedEditions;
    constructor Create();
    function GetInfoForCard(CardName: string): string;
    destructor Destroy; override;
  end;

implementation



{ TMKMCrawler }

constructor TMKMCrawler.Create;
begin
  FHTTP := TIdHTTP.Create;
  FHTTP.AllowCookies := True;
  FHTTP.HandleRedirects := True;
  FHTTP.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create;
end;

function TMKMCrawler.GetInfoForCard(CardName: string): string;

  function SearchForCard: string;
  var
    EncodedName, FinalUrl: string;
  begin
    // first encode name (because spaces etc.)
    EncodedName := TIdURI.ParamsEncode(CardName);
    // build url
    FinalUrl:=Format(MKMURL, [EncodedName]);
    // and download content
    Result := FHTTP.Get(FinalUrl);
  end;

var
  Content: string;
begin
  Content := SearchForCard;
  Result := Content;
end;

destructor TMKMCrawler.Destroy;
begin
  inherited Destroy;
end;

end.
